import os
import re

def main():
	files = os.listdir(r"./")
	with open("SUMMARY.md",'w',encoding='utf-8') as fp:
		index = 0
		for file in files:
			# 这是一个文件夹
			if file.startswith("chapter"):
				fp.write("* [第{}章：{}]({}/00.md)\n".format(index+1,file,file))
				# 获取这个文件夹的目录下的所有文件
				dirname = os.path.join("./",file)
				sections = sorted(os.listdir(dirname))
				for sidx,section in enumerate(sections):
					if sidx == 0:
						continue
					section_name = re.sub(r'\d',"",section)
					fp.write("	* [第{}节：{}]({}/{})\n".format(sidx,section_name,file,section))
			index += 1



if __name__ == '__main__':
	main()
	